package edu.thu.studio.ormdesigner.outline.action;

import org.eclipse.gef.ui.parts.TreeViewer;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.PlatformUI;

import edu.thu.studio.ormdesigner.outline.command.CreateDiagramCommand;
import edu.thu.studio.ormdesigner.outline.dialog.DiagramDialog;
import edu.thu.studio.ormdesigner.util.Properties;

public class CreateDiagramAction extends AbstractOutlineAction {
    
    public static final String ID = CreateDiagramAction.class.getName();
    
    public CreateDiagramAction(TreeViewer treeViewer) {
        super(ID, Properties.outline_menu_creatediagram, treeViewer);
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    public void execute(Event event) {
        
        DiagramDialog dialog = new DiagramDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), null);
        
        if (dialog.open() == IDialogConstants.OK_ID) {
            CreateDiagramCommand command = new CreateDiagramCommand(this.getORMModel(), dialog.getResult());
            this.execute(command);
        }
    }
    
}
